package com.dareway.reflex;

import java.lang.reflect.Type;

public class classloader {
    public static void main(String[] args) throws ClassNotFoundException {
        Class<String> clazz = String.class;   //使用class关键字，通过类名获取

        Class<?> clazz2 = Class.forName("java.lang.String");   //使用Class类静态方法forName()，通过包名.类名获取，注意返回值是Class<?>
        Class<?> clazz3 = new String("cpdd").getClass();  //通过实例对象获取

        System.out.println(clazz == clazz2);
        System.out.println(clazz == clazz3);


        Class<?> clazzInt = int.class;   //基本数据类型有Class对象吗？
        System.out.println(clazzInt);
        System.out.println(Integer.TYPE == int.class);
        System.out.println(Integer.TYPE == Integer.class); //false

        System.out.println(">>>>>>>>>>>clazzString>>>>>>>>>>>");
        Class<String[]> clazzString = String[].class;
        System.out.println(clazzString.getName());  //获取类名称（得到的是包名+类名的完整名称）
        System.out.println(clazzString.getSimpleName());
        System.out.println(clazzString.getTypeName());
        System.out.println(clazzString.getClassLoader());   //获取它的类加载器

        System.out.println(">>>>>>>>>>>class sup Interface>>>>>>>>>>>");
        Integer i = 10;
        for (Class<?> anInterface : i.getClass().getInterfaces()) {
            System.out.println(anInterface.getName());
        }

        for (Type genericInterface : i.getClass().getGenericInterfaces()) {
            System.out.println(genericInterface.getTypeName());
        }
    }
}
